/**
<<<<<<< HEAD
 * Created by Administrator on 2017/5/3.
=======
 * Created by cj on 2017/5/3.
>>>>>>> remotes/origin/master
 */

function ObserverList() {
    this.observerList = [];
}
<<<<<<< HEAD

ObserverList.prototype.Add = function (obj) {
    return this.observerList.push(obj);
}

OberverList.prototype.Empty = function () {
    this.oberverList = [];
}

OberverList.prototype.Count = function () {
    return this.observerList.length;
}

=======
ObserverList.prototype.Add = function (obj) {
    return this.observerList.push(obj);
};
ObserverList.prototype.Empty = function () {
    this.observerList = [];
};

ObserverList.prototype.Count = function () {
    return this.observerList.length;
};
>>>>>>> remotes/origin/master
ObserverList.prototype.Get = function (index) {
    if (index > -1 && index < this.observerList.length) {
        return this.observerList[index];
    }
};
ObserverList.prototype.Insert = function (obj, index) {
    var pointer = -1;
<<<<<<< HEAD
    if (index === 0) {
=======
    if (index ===  0) {
>>>>>>> remotes/origin/master
        this.observerList.unshift(obj);
        pointer = index;
    } else if (index === this.observerList.length) {
        this.observerList.push(obj);
        pointer = index;
    }
    return pointer;
};
ObserverList.prototype.IndexOf = function (obj, startIndex) {
    var i = startIndex, pointer = -1;
    while (i < this.observerList.length) {
        if (this.observerList[i] === obj) {
            pointer = i;
        }
        i++;
    }
    return pointer;
};
ObserverList.prototype.RemoveAt = function (index) {
    if (index === 0) {
        this.observerList.shift();
    } else if (index === this.observerList.length - 1) {
        this.observerList.pop();
    }
};
// Extend an object with an extension
function extend(extension, obj) {
    for (var key in extension) {
<<<<<<< HEAD
=======
        console.log(key);
>>>>>>> remotes/origin/master
        obj[key] = extension[key];
    }
}
//接着，我们对被观察者以及其增加，删除，通知在观察者列表中的观察者的能力进行建模：
function Subject() {
    this.observers = new ObserverList();
}
Subject.prototype.AddObserver = function (observer) {
    this.observers.Add(observer);
};
Subject.prototype.RemoveObserver = function (observer) {
    this.observers.RemoveAt(this.observers.IndexOf(observer, 0));
};
Subject.prototype.Notify = function (context) {
    var observerCount = this.observers.Count();
    for (var i = 0; i < observerCount; i++) {
<<<<<<< HEAD
        this.observers.Get(i).Update(context);
    }
};
//我们接着定义建立新的观察者的一个框架。这里的update函数之后会被具体的行为覆盖。
// The Observer
function Observer() {
    this.Update = function () {
        // ...
    };
}


=======
        console.log(context);
        this.observers.Get(i).Update(context);
    }
};
//我们接着定义建立新的观察者的一个框架。这里的update 函数之后会被具体的行为覆盖。
// The Observer
function Observer() {
    this.Update = function () {
// ...
    };
}
>>>>>>> remotes/origin/master
